package com.lw.mall.web.admin;

import com.lw.mall.entity.Evaluation;
import com.lw.mall.entity.pojo.ResultBean;
import com.lw.mall.service2.EvaluationService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/admin/comment")
public class CommentController {

    @Autowired
    private EvaluationService2 evaluationService2;
    /**
     * http://localhost:8081/mall/admin/comment/toList.html
     * 去页面
     */
    @GetMapping("/toList")
    public String commentList(){

        return "admin/comment/list";
    }

    /**
     * 评价总数
     * @return
     */
    @ResponseBody
    @RequestMapping("/getTotal.do")
    public ResultBean<Integer> getTotal() {
        final int total = evaluationService2.list().size();
        return new ResultBean<>(total);
    }

    @ResponseBody
    @RequestMapping("/list.do")
    public ResultBean list() {
        final List<Evaluation> list = evaluationService2.list();
        return new ResultBean(list);
    }

    @ResponseBody
    @RequestMapping("/del.do")
    public ResultBean<Boolean> del(int id) {
        evaluationService2.removeById(id);
        return new ResultBean<>(true);
    }

}
